package com.fjd.controller;

import com.fjd.dto.FollowDTO;
import com.fjd.dto.IMUserDTO;
import com.fjd.dto.MiniMallCheckDTO;
import com.fjd.dto.MiniMallDeleteDTO;
import com.fjd.entity.Follow;
import com.fjd.entity.LiveBroadcast;
import com.fjd.result.Result;
import com.fjd.service.LiveService;

import com.fjd.vo.AttentionVO;
import com.fjd.vo.LiveDataVO;
import com.fjd.vo.MerchandiseVO;
import com.fjd.vo.WatcherInitialVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.hssf.dev.ReSave;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/shopping/live")
@Slf4j
@Api(tags = "直播相关接口")
public class LiveController {

    @Autowired
    private LiveService liveService;

    @GetMapping("/minimall/list")
    @ApiOperation("根据主播id获取小商城列表")
    public Result<List<MerchandiseVO>> listminimall(String anchorId){
        List<MerchandiseVO> merchandiseVOList = liveService.listMinimallByAnchorId(anchorId);
        return Result.success(merchandiseVOList);
    }

    @GetMapping("/minimall/check")
    @ApiOperation("校验小商城内是否已经有该商品")
    public Result<Boolean> check(MiniMallCheckDTO miniMallCheckDTO){
        Boolean bool =  liveService.check(miniMallCheckDTO);
        return Result.success(bool);
    }

    @GetMapping("/minimall/add")
    @ApiOperation("往主播小商城中增加商品")
    public Result addToMall(MiniMallCheckDTO miniMallCheckDTO){
        liveService.add(miniMallCheckDTO);
        return Result.success();
    }

    @DeleteMapping("/minimall/delete")
    @ApiOperation("根据商品ID删除对应的小商品")
    public Result delete(@RequestBody MiniMallDeleteDTO miniMallDeleteDTO){
        liveService.delete(miniMallDeleteDTO);
        return Result.success();
    }

    @PostMapping("/IM/user/create")
    @ApiOperation("创建IM用户")
    public Result<Boolean> createIMUser(@RequestBody IMUserDTO imUserDTO){
        Boolean bool = liveService.createIMUser(imUserDTO);
        return Result.success(bool);
    }

    @GetMapping("/liveroom/list")
    @ApiOperation("获取正在直播的直播间列表")
    public Result<List<LiveBroadcast>> liverooms(){
        List<LiveBroadcast> broadcastList = liveService.listliveroom();
        return Result.success(broadcastList);
    }

    @GetMapping("/group/join")
    @ApiOperation("校验用户进入直播间")
    public Result<WatcherInitialVO> enterLiveRoom(String openId){
        WatcherInitialVO watcherInitialVO = liveService.enter(openId);
        return Result.success(watcherInitialVO);
    }

    @GetMapping("/status/{status}")
    @ApiOperation("修改直播间的状态")
    public Result liveStatus(@PathVariable String status){
        liveService.editLiveStatus(status);
        return Result.success();
    }

    @PostMapping("/follow")
    @ApiOperation("关注和取关主播")
    public Result follow(@RequestBody FollowDTO followDTO){
        liveService.follow(followDTO);
        return Result.success();
    }

    @GetMapping("/follow/list")
    @ApiOperation("列出我的关注")
    public Result<List<AttentionVO>> listAttention(){
        List<AttentionVO> attentionVOList = liveService.listAttention();
        return Result.success(attentionVOList);
    }

    @GetMapping("/follow/check")
    @ApiOperation("检验是否已经关注该主播")
    public Result<Follow> checkFollow(String toId){
        Follow follow = liveService.checkFollow(toId);
        return Result.success(follow);
    }

    @GetMapping("/follow/livedata")
    @ApiOperation("获取直播数据")
    public Result<LiveDataVO> getLiveData(){
        return Result.success(liveService.getLiveData());
    }


}


